/*
OpenMVL Matrix Vector Library
Copyright (c) 2009 FluidInteractive (R)
 
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising
from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
 
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must
not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
 
Written by: Nicola Candussi <nicola@fluidinteractive.com>
*/

//expr_scalar.hpp

#ifndef MVL_EXPR_SCALAR_HPP
#define MVL_EXPR_SCALAR_HPP

namespace mvl {

#include "layout.hpp"
#include "expr.hpp"

template<typename T, typename R, typename C, typename Order>
class expr_scalar : public expr< expr_scalar<T, R, C, Order> > 
{ 
public:
    typedef expr_scalar self_t;

public:
    typedef typename layout::dense_layout<R::value, C::value, Order> layout_t;
    typedef T                           value_type;
    typedef typename layout_t::order    order;
    typedef typename layout_t::Rows     Rows;
    typedef typename layout_t::Cols     Cols;
    typedef typename layout_t::Size     Size;

    typedef const self_t    const_closure_t;
    typedef const_closure_t closure_t;

public:
    expr_scalar(value_type value) : m_value(value) { };

    //access
    template<typename Entry>
    value_type at() const {
        return m_value;
    }

private:
    value_type m_value;
};

template<typename T, int R, int C>
struct scalar_mat_traits 
{
    typedef const expr_scalar<T, meta::int_<R>, meta::int_<C>, layout::row_major_tag> type;
};

template<typename T, int R, int C> 
inline 
typename scalar_mat_traits<T, R, C>::type
scalar_mat(T value) {
    typedef typename scalar_mat_traits<T, R, C>::type expr_t;
    return expr_t(value);
}

} // namespace mvl


#endif

